﻿using nj4x;
using nj4x.Metatrader;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace MT4
{

    public class Account
    {
        public String Login = "";
        public String Password = "";
        public String Broker = "";

        private static String server = "127.0.0.1";
        private static Int32 port = 7788;

        private Strategy strategy = new Strategy();

        public Account()
        {
        }

        public Account(String Login, String Password, String Broker)
            : this()
        {
            this.Login = Login;
            this.Password = Password;
            this.Broker = Broker;
        }

        public Account(String Login, String Password, String Broker, Strategy strategy)
            : this(Login, Password, Broker)
        {
            this.strategy = strategy;
        }

        public void Connect()
        {
            strategy.Connect(server, port, new Broker(Broker), Login, Password);
        }

        public Strategy Strategy()
        {
            return strategy;
        }

        public List<IOrderInfo> getOpenTrades()
        {
            List<IOrderInfo> orders = new List<IOrderInfo>();
            for (int i = 0; i < strategy.OrdersTotal(); i++)
                orders.Add(strategy.OrderGet(i, SelectionType.SELECT_BY_POS, SelectionPool.MODE_TRADES));
            return orders;
        }

    }
}
